4 // Table of contents toggle
5 mw
.hook( 'wikipage.content' ).add( function ( $content
) {
6 $content
.find( '.toc' ).addBack( '.toc' ).each( function () {
9 $tocToggleCheckbox
= $this.children( '.toctogglecheckbox' ),
10 $tocTitle
= $this.find( '.toctitle' ),
11 $tocToggleLink
= $this.find( '.togglelink' ),
12 $tocList
= $this.find( 'ul' ).eq( 0 );
14 // Hide/show the table of contents element
15 function toggleToc() {
16 if ( $this.hasClass( 'tochidden' ) ) {
17 // FIXME: Use CSS transitions
18 // eslint-disable-next-line no-jquery/no-slide
19 $tocList
.slideDown( 'fast' );
20 $tocToggleLink
.text( mw
.msg( 'hidetoc' ) );
21 $this.removeClass( 'tochidden' );
22 mw
.cookie
.set( 'hidetoc', null );
24 // eslint-disable-next-line no-jquery/no-slide
25 $tocList
.slideUp( 'fast' );
26 $tocToggleLink
.text( mw
.msg( 'showtoc' ) );
27 $this.addClass( 'tochidden' );
28 mw
.cookie
.set( 'hidetoc', '1' );
32 // Only add it if there is a complete TOC and it doesn't
33 // have a toggle added already
34 if ( !$tocToggleCheckbox
.length
&& $tocTitle
.length
&& $tocList
.length
&& !$tocToggleLink
.length
) {
35 hideToc
= mw
.cookie
.get( 'hidetoc' ) === '1';
37 $tocToggleLink
= $( '<a>' )
42 .addClass( 'togglelink' )
43 .text( mw
.msg( hideToc
? 'showtoc' : 'hidetoc' ) )
44 .on( 'click keypress', function ( e
) {
47 e
.type
=== 'keypress' && e
.which
=== 13
55 .wrap( '<span class="toctoggle"></span>' )
63 $this.addClass( 'tochidden' );